<?php 
include ('header.php');
$result = $db->query("SELECT COUNT(post_id) FROM ".$table_prefix."posts");
$result2 = $db->query("SELECT COUNT(topic_id) FROM ".$table_prefix."topics");
$result3 = $db->query("SELECT COUNT(user_id) FROM ".$table_prefix."users");
$result4 = $db->query("SELECT * FROM ".$table_prefix."topics WHERE topic_status <=1 ORDER BY view DESC LIMIT 10");
$result5 = $db->query("SELECT * FROM ".$table_prefix."topics WHERE topic_status <=1 ORDER BY reply DESC LIMIT 10");

$result6 = $db->query("SELECT * FROM ".$table_prefix."users WHERE user_id !=1 ORDER BY user_posts DESC LIMIT 10");

$result7 = $db->query("SELECT * FROM ".$table_prefix."users ORDER BY user_date DESC LIMIT 1");
$qqq=7;
$pageTitle = 'Statistics';
if (!$result)
{echo "$l_error_occured";}
else
{
$p= $db->fetch_array($result,'assoc');
$t= $db->fetch_array($result2,'assoc');
$u= $db->fetch_array($result3,'assoc');

$topics = $t['COUNT(topic_id)']-1;
$posts = $p['COUNT(post_id)']-$topics;
$users = $u['COUNT(user_id)']-1;

$newuser = $db->fetch_array($result7,'assoc');

echo "<div align='center'><table style='width:60%;'><tr><th><b><div align='center'>$l_forumname - Statistics Center</b></div></th></tr></table>
<br>
<table style='width:60%;' border=1>
<tr><th>&nbsp;<b><img src='./img/misc/normal.gif' align='absmiddle'> General statistics</b></th></tr><td>
<br>&nbsp;Total Members: $users<br><br>
&nbsp;Total Posts: $posts<br><br>
&nbsp;Total Topics: $topics<br><br>
&nbsp;Latest member registered is <a href='user.php?u=$newuser[user_id]'><b>$newuser[user_name]</b></a><br><br></td></tr>

<tr><th>&nbsp;<b><img src='./style/$default_style/img/quick_sticky.gif' align='absmiddle'> Top 10 Posters</b></th></tr>
<tr><td><br>";
//TOP 10 users
while ($userreplies = $db->fetch_array($result6,'assoc')) {
echo "&nbsp;<a href='user.php?u=$userreplies[user_id]'>$userreplies[user_name]</a> ($userreplies[user_posts])<br><br>";
}
//TOP 10 topics (reply)
echo "<br></td></tr><tr><th>&nbsp;<b><img src='./style/$default_style/img/normal_post.gif' align='absmiddle'> Top 10 Topics (by Replies)</b></th></tr><tr><td><br>";

while ($mostreplies = $db->fetch_array($result5,'assoc')) {
echo "&nbsp;<a href='topic.php?t=$mostreplies[topic_id]'>".trim($mostreplies['topic_subject'])."</a> ($mostreplies[reply])<br><br>";
}
//TOP 10 topics (view)
echo "<br></td></tr><tr><th>&nbsp;<b><img src='./style/$default_style/img/more_pages_view.gif' align='absmiddle'> Top 10 Topics (by Views)</b></th></tr><tr><td><br>";
while ($mostview = $db->fetch_array($result4,'assoc')) {
echo "&nbsp;<a href='topic.php?t=$mostview[topic_id]'>".trim($mostview['topic_subject'])."</a> ($mostview[view])<br><br>";
}
echo "</table></div><br>";
echo "<br>";

}

include 'footer.php';
$pageContents = ob_get_contents();
ob_end_clean();
echo str_replace('<!--TITLE-->', $pageTitle, $pageContents);
?>